package cn.edu.sgu.www.mhxysy.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.function.Consumer;

/**
 * @author 沐雨橙风ιε
 * @version 1.0
 */
@Component
public class ImageUpdater {

    private final UploadUtils uploadUtils;

    @Autowired
    public ImageUpdater(UploadUtils uploadUtils) {
        this.uploadUtils = uploadUtils;
    }

    public void updateImageById(String image, Consumer<Object> consumer) {
        // 删除图片后缀：?timestamp=
        int index = image.indexOf("?");

        if (index > 0) {
            image = image.substring(0, index);
        }

        if (uploadUtils.moveFile(image)) {
            consumer.accept(null);
        }
    }

}